#include <zmq.hpp>
#include <iostream>
#include <chrono>
#include <string>

int main() {
    zmq::context_t context{1};
    zmq::socket_t socket{context, zmq::socket_type::pull};
    socket.connect("ipc:///tmp/test_ipc");

    while (true) {
        zmq::message_t zmq_message;
        socket.recv(zmq_message, zmq::recv_flags::none);

        // 获取当前时间作为接收时间戳
        auto end_time = std::chrono::high_resolution_clock::now();
        auto receive_timestamp = std::chrono::duration_cast<std::chrono::microseconds>(end_time.time_since_epoch()).count();

        // 将接收到的消息转换为字符串
        std::string message(static_cast<char*>(zmq_message.data()), zmq_message.size());

        // 将消息转换为时间戳
        auto send_timestamp = std::stoll(message);

        // 计算延时
        auto delay = receive_timestamp - send_timestamp;
        std::cout << "Message delay: " << delay << " microseconds" << std::endl;
    }

    return 0;
}
